home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 January / macformat-033.iso / mac / Shareware City / Developers / ABox.v1.8 / CPlus Files / ABUString.c < prev    next >
Encoding:
Text File  |  1995-05-23  |  5.0 KB  |  225 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
  8.     See the Modification History for more details.
  9.  
  10. Product
  11.     About Box
  12.  
  13. FILE
  14.     ABUString.c
  15.  
  16. NAME
  17.     ABUString.c, part of the ABox project source code,
  18.     responsible for mix-in handling the AboutBox string stuff.
  19.  
  20. DESCRIPTION
  21.     This file contains defines for the about box modules.
  22.     
  23. DEVELOPED BY
  24.     George (ty) Tempel                netromancr@aol.com
  25.     All code in this file, and its associated header file was
  26.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  27.     "FilterTop" application development, except where noted.
  28.     
  29.     This file is based, in part, upon prior work by
  30.     Greg Anderson <greggor@apple.com> of Apple DTS.
  31.  
  32.  
  33. CARETAKER - George (ty) Tempel <netromancr@aol.com>
  34.      Please consult this person for any changes or suggestions to this file.
  35.  
  36. MODIFICATION HISTORY
  37.  
  38.     dd mmm yy    -    xxx    -    patchxx: description of patch
  39.     10 June 94    -    ty    -    Initial Version Created
  40.     20-july-94    -    ty    -    initial version released
  41.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  42.                             release and the associated Universal Headers from Apple:
  43.                             most methods that returned references now have "Ref" at
  44.                             the end of their methods names to prevent possible collisions
  45.                             with datatypes and classes of the same name (older versions
  46.                             of the compiler didn't have a problem with this).
  47.  
  48. */
  49.  
  50. /*==============================================================================*/
  51.  
  52. /*======= Segmentation directives ========*/
  53.  
  54. //#pragma segment ty
  55.  
  56. /*============ Header files ==============*/
  57.  
  58. #include     "ABUString.h"
  59. #include    "ABoxDefs.h"
  60.  
  61. /*=============== Globals ================*/
  62.  
  63.  
  64. /*================ CODE ==================*/
  65.  
  66.  
  67. /*=============== Globals ================*/
  68.  
  69.  
  70. /*================ CODE ==================*/
  71.  
  72.  
  73. /*=============================== ABUString::ABUString ================================*/
  74. ABUString::ABUString(void)
  75. {
  76. }    // end ABUString
  77.  
  78.  
  79. /*=============================== ABUString::~ABUString ================================*/
  80. ABUString::~ABUString(void)
  81. {
  82. }    // end ~ABUString
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. /*=============================== ABUString::P2Ccpy ==================================*/
  90. //
  91. //    Copy a pascal style string into a C string; if either parameter
  92. //    is bad the routine does nothing.
  93. //
  94. void    ABUString::P2Ccpy(char *c, Str255 p)
  95. {
  96.     short    index;
  97.     
  98.     //    begin here...
  99.     
  100.     if (!(c && p))
  101.         return;
  102.     else
  103.         index = p[0];
  104.     
  105.     //    copy from back to front
  106.     c[index] = '\0';
  107.     
  108.     while (index > 0)
  109.     {
  110.         c[index - 1] = p[index];    //    pascal strings _start_ w/length byte
  111.         --index;
  112.     } // end while loop
  113.     
  114. } // end P2Ccpy
  115.  
  116.  
  117.  
  118. /*=============================== ABUString::C2Pcpy ==================================*/
  119. //
  120. //    Copy a C string into a Pascal string; if either parameter
  121. //    is bad the routine does nothing.
  122. //
  123. void    ABUString::C2Pcpy(Str255 p, char *c)
  124. {
  125.     short    index = 0;
  126.     
  127.     const short    kPMax = 255;        //    max length of an Str255
  128.     
  129.     //    begin here...
  130.     
  131.     if (!(c && p))
  132.         return;
  133.     
  134.     while((*c) && (index < kPMax))
  135.         p[index++] = *c++;
  136.     p[0] = index - 1;
  137. }    //    end of C2Pcpy
  138.  
  139.  
  140. /*=============================== ABUString::PCcmp ==================================*/
  141. //
  142. //    Compare a Pascal string with a C string, returning the same values
  143. //    that strcmp() would if we were dealing with strictly C-style strings.
  144. //
  145. short ABUString::PCcmp(Str255 p, char *c)
  146. {
  147.     Str255        tempString;
  148.     short        result;
  149.     
  150.     //    begin here...
  151.     if (!(p && c))
  152.     {
  153.         if (p && !c)
  154.             return 1;
  155.         else if (!p && c)
  156.             return -1;
  157.         else
  158.             return 0;
  159.     } 
  160.     else 
  161.     {    
  162.         C2Pcpy(tempString, c);
  163.         result = EqualString(p, tempString, kABcaseInsensitive, kABdiacriticalInsensitive);    // in OSUtils.h
  164.         return result;
  165.     } // end if else block
  166. }    //    end PCcmp()
  167.  
  168.  
  169.  
  170.  
  171.  
  172. /*=============================== ABUString::P2Pstrcat ==================================*/
  173. //
  174. //    Copy a Pascal string onto the tail end of another (append), returning the 
  175. //    newly created string.
  176. //
  177. //    Any problems with the parameters is reflected in the output string; if
  178. //    both inputs are bad, the output is NULL; if the source is bad, the
  179. //    output is the destination string; if the destination is bad, the output
  180. //    is the source.
  181. //
  182. StringPtr ABUString::P2Pstrcat(Str255 dest, Str255 src)
  183. {
  184.     unsigned char        *destPtr;
  185.     unsigned char        *srcPtr;
  186.     unsigned char        *tPtr;
  187.     short                index;
  188.     short                max;
  189.     const short            kPMax = sizeof(Str255);        //    max length of an Str255
  190.     
  191.     //    begin here...
  192.     
  193.     if (!(dest && src))
  194.         if (dest && !src)
  195.             return dest;
  196.         else if (!dest && src)
  197.             return src;
  198.         else
  199.             return NULL;
  200.     
  201.     srcPtr = (unsigned char*) src;
  202.     destPtr = (unsigned char*) dest;
  203.     max = *srcPtr;
  204.     
  205.     // Adjust past length & chars already in dest
  206.  
  207.     tPtr = destPtr + *destPtr + 1;
  208.     ++srcPtr;
  209.  
  210.     // Determine how many characters we can really copy
  211.  
  212.     if(max + *destPtr > kPMax)
  213.         max = kPMax - *destPtr;
  214.     *destPtr += max;
  215.     
  216.     for(index = 0; index < max ; ++index)
  217.         *tPtr++ = *srcPtr++;
  218.     
  219.     return dest;
  220.     
  221. }    //    end of P2Pstrcat()
  222.  
  223.  
  224. //    end of file.
  225.